package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.CapBacDto;
import com.tt.fashionWebSite.dto.JsonResponseCode;
import com.tt.fashionWebSite.dto.JsonResponseDto;
import com.tt.fashionWebSite.service.Ad_MemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_MemberLevelController {
    @Autowired
    private Ad_MemberLevelService ad_memberLevelService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adMemberLevel", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminMemberLevel(HttpServletRequest request, @RequestBody CapBacDto levelDto) {
        return new JsonResponseDto<Integer>(ad_memberLevelService.adminMemberLevel(levelDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllLevel", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<CapBacDto>> getAllLevel(HttpServletRequest request) {
        return new JsonResponseDto<List<CapBacDto>>(ad_memberLevelService.getAllLevel(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toLevelMemberPage/{maCB}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageMemberLevel(HttpServletRequest request, @PathVariable String maCB, Map<String, Object> map) throws ParseException {
        map.put("maCB", maCB);
        return new ModelAndView("admin/ad-member-level-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editLevelMember", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<CapBacDto> getLevelInfoEdit(HttpServletRequest request, @RequestBody CapBacDto levelDto) {
        return new JsonResponseDto<CapBacDto>(ad_memberLevelService.getLevelInfoEdit(levelDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerLevelEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<CapBacDto> registerLevelEdit(HttpServletRequest request, @RequestBody CapBacDto levelDto) {
        return new JsonResponseDto<CapBacDto>(ad_memberLevelService.registerLevelEdit(levelDto), JsonResponseCode.SUCCESS);
    }
}